from typing import List


# Definition for a binary tree node.
class TreeNode:
    def __init__(self, val=0, left=None, right=None):
        self.val = val
        self.left = left
        self.right = right
        
class Solution:
    def findFrequentTreeSum(self, root: TreeNode) -> List[int]:
        ma = {}
        def dfs(node):
            if node is None:
                return 0
            su = node.val + dfs(node.left) + dfs(node.right)
            if su in ma:
                ma[su] += 1
            else:
                ma[su] = 1
            return su
        dfs(root)
        
        ans = []
        mx = 0
        for su in ma:
            cnt = ma[su]
            if cnt > mx:
                mx = cnt
                ans = []
            if mx == cnt:
                ans.append(su)
        return ans
            